package com.gongpingjialoan.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.AppCompatEditText;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.car.BuyCarVipActivity;

/**
 * Created by Administrator on 2016/3/21.
 */
public class VipBuycarFilterPopupWindow extends PopupWindow implements View.OnClickListener {

    private View view;

    private View emptyView;

    private AppCompatEditText mAppCompatEditText;

    private Button mButton;

    private BuyCarVipActivity mBuyCarVipActivity;

    public VipBuycarFilterPopupWindow(Activity context) {
        super(context);
        this.mBuyCarVipActivity = (BuyCarVipActivity) context;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.others_layout, null);
        emptyView = view.findViewById(R.id.view);
        mAppCompatEditText = (AppCompatEditText) view.findViewById(R.id.needview);
        mButton = (Button) view.findViewById(R.id.button);
        mButton.setOnClickListener(this);
        emptyView.setOnClickListener(this);
        //设置SelectPicPopupWindow的View
        this.setContentView(view);

        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.PopupMenu);
//        listView.setOnItemClickListener(this);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable cd = new ColorDrawable(0x000000);
        this.setBackgroundDrawable(cd);
    }


    @Override
    public void onClick(View v) {
        if (v == emptyView) {
            dismiss();
        }
        if(v == mButton){
            String msg = mAppCompatEditText.getText().toString();
            if(!TextUtils.isEmpty(msg)){
                mBuyCarVipActivity.mNoIntentFragment.otherNeed(msg);
                dismiss();
            }else {
                Toast.makeText(mBuyCarVipActivity, "输入您的需求", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
